package top.infopub.security.util;


import org.springframework.util.DigestUtils;

import java.util.Calendar;

public class TokenMD5Utils {

    public static String pwdMD5(String yz,String code){
        //加密验证值生成规则:
        //MD5(yyyy+盐值+mm+盐值+dd+MD5(7位工号))
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);//获取年份
        int month=cal.get(Calendar.MONTH)+1;//获取月份
        int day=cal.get(Calendar.DATE);//获取日
        String month_str=month+"";
        String day_str=day+"";
        if(month<10){
            month_str="0"+month;
        }
        if(day<10){
            day_str="0"+day;
        }
        String codeMd5= DigestUtils.md5DigestAsHex(code.getBytes());
        String str=year+yz+month_str+yz+day_str+codeMd5;
        return DigestUtils.md5DigestAsHex(str.getBytes());
    }

    public static String pwdMD5(String yz,String code,String dayTime){
        //加密验证值生成规则:
        //MD5(yyyy+盐值+mm+盐值+dd+MD5(7位工号))
        String[] s = dayTime.split("-");
        String year = s[0];
        String month= s[1];;//获取月份
        String day= s[2];//获取日
        String codeMd5= DigestUtils.md5DigestAsHex(code.getBytes());
        String str=year+yz+month+yz+day+codeMd5;
        return DigestUtils.md5DigestAsHex(str.getBytes());
    }


}
